package com.wu.controller;

import com.wu.pojo.FriendLink;
import com.wu.pojo.model.DateYear;
import com.wu.response.CommonReturnType;
import com.wu.service.ArticlesService;
import com.wu.service.FriendLinkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author: 吴磊
 * @program: blog
 * @create: 2021-04-24 08:10
 */
@RestController
@Api(tags = "页面加载事件")
public class LoadController {
    @Autowired
    private ArticlesService articlesService;

    @Autowired
    private FriendLinkService friendLinkService;

    /**
     * 获取今日推荐的5篇文章
     *
     * @return
     */
    @ApiOperation(value = "获取今日推荐的5篇文章")
    @RequestMapping(value = "/getRecommend", method = RequestMethod.POST)
    public CommonReturnType getRecommend() {
        Map<String, Object> map = articlesService.getRecommend();
        return CommonReturnType.create(map);
    }

    /**
     * 获取用户今日推荐的5篇文章
     *
     * @return
     */
    @ApiOperation(value = "获取用户今日推荐的5篇文章")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户Id", required = true, dataTypeClass = String.class)
    })
    @RequestMapping(value = "/getRecommendByUserId", method = RequestMethod.POST)
    public CommonReturnType getRecommendByUserId(@RequestParam("userId") String userId) {
        Map<String, Object> map = articlesService.getRecommendByUserId(userId);
        return CommonReturnType.create(map);
    }


    /**
     * 获取所有时间的分类
     *
     * @return
     */
    @ApiOperation(value = "获取用户的所有时间的分类")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户Id", dataTypeClass = String.class)
    })
    @RequestMapping(value = "/getAllDate", method = RequestMethod.POST)
    public CommonReturnType getAllDate(@RequestParam(name = "userId") String userId) {
        List<DateYear> aLlDate = articlesService.getALlDate(userId);
        return CommonReturnType.create(aLlDate);
    }

    /**
     * 获取文章数量
     *
     * @param userId，如果为空就返回全部的数量，如果不为空就返回对应用户的文章数量
     * @return
     */
    @ApiOperation(value = "获取文章数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "如果为空就返回全部的数量，如果不为空就返回对应用户的文章数量", dataTypeClass = String.class)
    })
    @RequestMapping(value = "/getCount", method = RequestMethod.POST)
    public CommonReturnType getArticleCount(@RequestParam(name = "userId", required = false) String userId) {
        return CommonReturnType.create(articlesService.getArticleCount(userId));
    }

    /**
     * 获取所有的友情链接
     *
     * @return
     */
    @ApiOperation(value = "获取所有的友情链接")
    @RequestMapping(value = "/getlink", method = RequestMethod.POST)
    public CommonReturnType getAllFriendLink() {
        List<FriendLink> link = friendLinkService.getAllFriendLink();
        return CommonReturnType.create(link);
    }
}
